package com.example.personalcenter.model;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.personalcenter.model.MyItem;

import java.util.ArrayList;
import java.util.List;

public class UserViewModel extends ViewModel {
    private final MutableLiveData<List<MyItem>> items = new MutableLiveData<>(new ArrayList<>());

    public LiveData<List<MyItem>> getItems() { return items; }

    public void loadItems() {
        List<MyItem> list = new ArrayList<>();
        for (int i = 1; i <= 20; i++) {
            list.add(new MyItem("标题 " + i, "第 " + i + " 条描述"));
        }
        items.setValue(list);
    }

    public void deleteItem(MyItem target) {
        List<MyItem> curr = items.getValue();
        if (curr == null) return;
        List<MyItem> copy = new ArrayList<>(curr);
        copy.remove(target);
        items.setValue(copy);
    }
}